package com.itheima.core.service.impl;

import com.itheima.core.dao.RoleDao;
import com.itheima.core.dao.RoleRightDao;
import com.itheima.core.po.Function;
import com.itheima.core.po.FunctionRight;
import com.itheima.core.po.Role;
import com.itheima.core.po.RoleRight;
import com.itheima.core.service.RoleRightService;
import com.itheima.core.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * 用户Service接口实现类
 */
@Service("roleRightService")
@Transactional
public class RoleRightServiceImpl implements RoleRightService {
	// 注入UserDao
	@Autowired
	private RoleRightDao roleRightDao;


	@Override
	public List<RoleRight> findZtree() {
		List<RoleRight> ztree = roleRightDao.findZtree();
		return ztree;
	}

	@Override
	public String[] findChecked(Integer id) {
		return roleRightDao.findChecked(id);
	}

	@Override
	public Integer clearRight(Integer id) {
		return roleRightDao.clearRight(id);
	}

	@Override
	public Integer saveRoleRight(Integer id, String[] rights) {
		List<RoleRight> roleRights = new ArrayList<>();
		for (String right : rights) {
			RoleRight roleRight = new RoleRight();
			roleRight.setId(right);
			roleRights.add(roleRight);
		}
		return roleRightDao.saveRight(id,roleRights);
	}

	@Override
	public List<RoleRight> findAllFunctionNodes() {
		return roleRightDao.findAllFunctionNodes();
	}

	@Override
	public Function findFunctionById(String function_id) {
		return roleRightDao.findFunctionById(function_id);
	}

	@Override
	public List<Function> findSubmoduleById(String parent_id) {
		return roleRightDao.findSubmoduleById(parent_id);
	}

	@Override
	public List<FunctionRight> findFunctionRightById(String function_id) {
		return roleRightDao.findFunctionRightById(function_id);
	}
}
